package com.shenmazong.demoredistest.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @program: server-java-demo
 * @description: RedisTemplateConfig
 * @author: 亮子说编程
 * @create: 2020-11-12 21:07
 **/
@Configuration
public class RedisTemplateConfig {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
    * @Description: 解决存储乱码问题
    * @Param: []
    * @return: org.springframework.data.redis.core.RedisTemplate
    * @Author: 亮子说编程
    * @Date: 2020/11/12 21:09
    */
    @Bean
    public RedisTemplate redisTemplateInit() {
        //设置序列化Key的实例化对象
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //设置序列化Value的实例化对象
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return redisTemplate;
    }
}
